﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using GodPl.GameObjects;
using GodPl.GameObjects.Creatures;

namespace GodPl
{
    public partial class GameScreen : Form
    {

        GodPlGame game;

        public GodPlGame Game
        {
            set { game = value; }
            get { return game; }
        }

        public GameScreen()
        {
            InitializeComponent();
        }


        public IntPtr DrawSurface
        {
            get { return pctSurface.Handle; }
        }

        private void GameScreen_Load(object sender, EventArgs e)
        {
            
        }

        private void GameScreen_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void GameScreen_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();
        }

        private void btnPause_Click(object sender, EventArgs e)
        {
            
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            GodPlGame.World.AddRandomBriyya();
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {

        }

        private void pctSurface_Click(object sender, EventArgs e)
        {
            //var ce = (ControlEventArgs)e;

            System.Drawing.Point upperLeft = new System.Drawing.Point(pctSurface.Top, pctSurface.Left);
            System.Drawing.Point cursor = Cursor.Position;
            var pCoords = this.PointToClient(Cursor.Position);
            //System.Drawing.Point pCoords = new System.Drawing.Point(cursor.X - upperLeft.X - this.Left,
            //                                                        cursor.Y - upperLeft.Y - this.Top);

            foreach (GameObject o in GodPlGame.World.GameObjects)
            {
                Briyya b = o as Briyya;
                if (b != null &&
                    b.BoundingRectangle.Contains(pCoords.X, pCoords.Y))
                {
                    nudSelector.Value = b.Id;
                    //nudSelector.Validate(false);
                    return;
                }
            }

        }

        private void nudSelector_ValueChanged(object sender, EventArgs e)
        {
            GodPlGame.UpdateWidgets();
        }



        


    }
}
